package com.linghu.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.linghu.entity.Teacher;
import com.linghu.resp.Result;
import com.linghu.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * @author linghu
 * @date 2024/4/16 15:37
 */
@RestController
@RequestMapping("/query")
public class QueryTeacherApi {
    @Autowired
    private TeacherService teacherService;

    /**
     * @Description: 查询所有教师信息API
     * @param
     * @return: com.linghu.resp.Result<?>
     * @Author: codelinghu
     * @Date: 2024/4/16
     */
    @GetMapping("/allTeacher")
    @ResponseBody
    public Result<?> QueryAll(){
        List<Teacher> list = teacherService.list(null);
        return Result.success(list);
    }


    /**
     * @Description: 根据院系条件查询教师信息~
     * @param teacher
     * @return: com.linghu.resp.Result<?>
     * @Author: codelinghu
     * @Date: 2024/4/16
     */
    @PostMapping("/SomeTeacher")
    @ResponseBody
    public Result<?> QueryConditionInfo(@RequestBody Teacher teacher){
        QueryWrapper<Teacher> wrapper = new QueryWrapper<>();
        if (teacher.getDepartment().equals("全部")){
            List<Teacher> list = teacherService.list(null);
            return Result.success(list);
        }
        wrapper.like("department",teacher.getDepartment());
        List<Teacher> list = teacherService.list(wrapper);
        return Result.success(list);
    }

    /**
     * @Description: 教师排行榜，降序排序~
     * @param
     * @return: com.linghu.resp.Result<?>
     * @Author: codelinghu
     * @Date: 2024/4/18
     */
    @GetMapping("/SortPost")
    @ResponseBody
    public Result<?> QuerySortInfo(){
        QueryWrapper<Teacher> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc(true,"positive_rate");
        List<Teacher> list = teacherService.list(wrapper);
        return Result.success(list);
    }


}
